package springboot.test3.demo.utils;


import org.apache.commons.codec.digest.DigestUtils;
import org.springframework.stereotype.Component;

/**
 * @版本号 1.0
 * @开发者: dongdq
 * @创建时间: 2021/11/2 18:24
 * @Content:
 */
@Component
public class MD5Util {

    public static  String md5(String str){
        return DigestUtils.md5Hex(str);
    }

    private static final String salt="1a2b3c4d";

    public static String inputPass(String formPass){
        String str = salt.charAt(0)+salt.charAt(2)+formPass;
        return md5(str);
    }

    public static String formPassToDBPass(String formPass, String salt){
        return md5(salt.charAt(0)+salt.charAt(2)+formPass);
    }

    public static String inputPassToDBPass(String inputPass, String salt){

        String fromPass = inputPass(inputPass);
        String dbPass = formPassToDBPass(fromPass,salt);
        return dbPass;
    }

}
